package servlet;

import bean.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet(name="ExitBlogServlet",urlPatterns = "/ExitBlogServlet")
public class ExitBlogServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException{
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");/*防止乱码*/
        String exit=request.getParameter("exit");
        if(exit.equals("exit")){
            System.out.println("退出成功");
            request.getSession().setAttribute("userArticles",new ArrayList<>());/*用户博客信息*/
            request.getSession().setAttribute("userCollections", new ArrayList<>());/*用户收藏的博客*/
            request.getSession().setAttribute("userCollected",new ArrayList<>());/*用户收藏*/
            request.getSession().setAttribute("userLikes",new ArrayList<>());/*用户点赞的博客*/
            request.getSession().setAttribute("userLiked",new ArrayList<>());/*用户点赞*/
            request.getSession().setAttribute("userCategories",new ArrayList<>());/*用户目录*/
            request.getSession().setAttribute("userLabels",new ArrayList<>());/*用户标签*/
            request.getSession().setAttribute("userPaginate",new ArrayList<>());/*分页信息*/
            request.getSession().setAttribute("allPage",1);/*分页数量*/
            request.getSession().setAttribute("page",1);
            request.getSession().setAttribute("user", new User());/*用户信息*/
        }else{
            System.out.println("退出失败");
        }
    }
}
